import axios from 'axios'
export default {
    namespaced: true,
    state: {
        waitFilms: []
    },
    mutations: {
        getWaitFilmsData(state, data) {
            if (data.lit == 10) {
                state.waitFilms = data.res.data.coming
            } else if (data.lit == 20 || data.lit == 30) {
                console.log(state.waitFilms);
                
                for (let i = 0; i < data.res.data.movies.length; i++) {
                    let z = 0
                    for (let j = 0; j < state.waitFilms.length; j++) {
                        if (data.res.data.movies[i].id !== state.waitFilms[j].id) {
                            z++ 
                        }else {
                            continue
                        }
                    }
                    if(z == state.waitFilms.length) {
                        state.waitFilms.push(data.res.data.movies[i])
                    }
                }
            }
        }
    },
    actions: {
        getWaitFilmsData({
            commit
        }, lit) {
            console.log(lit);
            if (lit == 10) {
                axios({
                    url: `/mmdb/movie/v2/list/rt/order/coming.json?ci=20&limit=10`,
                    methods: 'GET',
                }).then(res => {
                    commit('getWaitFilmsData', {
                        res: res.data,
                        lit: lit
                    })
                })
            } else if (lit == 20) {
                axios({
                    url: `/mmdb/movie/list/info.json?ci=20&movieIds=1211382%2C1346626%2C1383416%2C1278054%2C337487%2C1368406%2C93%2C18167%2C360%2C1298864`,
                    methods: 'GET',
                }).then(res => {
                    commit('getWaitFilmsData', {
                        res: res.data,
                        lit: lit
                    })
                })
            } else if (lit == 30) {
                axios({
                    url: `/mmdb/movie/list/info.json?ci=20&movieIds=1352470%2C1211143%2C1396491%2C1320617%2C1302015%2C1218187%2C1250964%2C428%2C1188366%2C1229068`,
                    methods: 'GET',
                }).then(res => {
                    commit('getWaitFilmsData', {
                        res: res.data,
                        lit: lit
                    })
                })
            }
        }
    }

}